package sel.me.spring.boot245.web.config.security.handler;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;
import sel.me.spring.boot245.web.exception.UnifyStrErrorCode;
import sel.me.spring.boot245.web.utils.ResultUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 用户未登录处理类
 * @author shenenlu
 * @date 2021-7-28 19:03
 */
@Component
public class UserAuthenticationEntryPointHandler implements AuthenticationEntryPoint {

    /**
     * 用户未登录返回结果
     */
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception){
        ResultUtil.responseJson(response, ResultUtil.resultError(UnifyStrErrorCode.UN_LOGIN));
    }
}
